package com.cxl.demo.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUpd {
    public String  Data(String timeTable){
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String string = timeTable;
        Date date = null;
        try{
            date = sdf1.parse(string);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("Date:"+date);

        SimpleDateFormat sdf2 = new SimpleDateFormat("EEEE");

        String week = sdf2.format(date);
        System.out.println(date);
        return week;
    }


    public static String getDate(){

        Date date= new Date();
        String timestamp = String.valueOf(date.getTime());


        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime =timestamp;
        long l = Long.parseLong(currentTime);
        String format = sdf.format(l);
        return format;
    }


    public String UploadDate(String timestamp){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime =timestamp;
        long l = Long.parseLong(currentTime);
        String format = sdf.format(l);
        return format;
    }



    public static Integer getNum(String timestamp1,String timestamp2){

     //   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //String currentTime =timestamp;
       // long l = Long.parseLong(currentTime);
       // String format = sdf.format(l);
        //return format;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1= null;
        Date date2=null;
       // Long t1=null ,t2=null;
        try {
            date1 = simpleDateFormat.parse(timestamp1);
            date2=simpleDateFormat.parse(timestamp2);

//            t1=Long.parseLong(String.valueOf(date1.getTime()));
//            t2=Long.parseLong(String.valueOf(date2.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }


        int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
        return days;

    }

}
